#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        int hash[26] = { 0 };
        for (auto e : p)
        {
            hash[e - 'a']++;
        }
        int hash1[26] = { 0 };
        vector<int> ret;
        for (int right = 0, left = 0, count = 0; right < s.size(); right++)
        {
            char in = s[right];
            hash1[in - 'a']++;
            if (hash1[in - 'a'] <= hash[in - 'a']) count++;
            if (right - left + 1 > p.size())
            {
                char out = s[left];
                if (hash1[out - 'a'] <= hash[out - 'a'])count--;
                hash1[out - 'a']--;
                left++;
            }
            if (count == p.size())
                ret.push_back(left);

        }
        return ret;
    }
};
